# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=moar
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.31.7
pkgrel=1
pkgdesc='Terminal pager program (mingw-w64)'
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/walles/moar'
license=('spdx:BSD-2-Clause')
makedepends=("${MINGW_PACKAGE_PREFIX}-go" "${MINGW_PACKAGE_PREFIX}-cc")
options=('!strip')
source=("https://github.com/walles/moar/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('02e7f8c7f6163380eb444ae45bf353c644a260bb30b9b60a18fef4b028b847e4')

build() {
    export GOOS=windows
    export GOROOT=${MINGW_PREFIX}/lib/go
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    export CGO_LDFLAGS="${LDFLAGS}"
    export GO_LDFLAGS="-s -w"
    export GOFLAGS="-trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external"
    case "${CARCH}" in
      x86_64)
        GOFLAGS+=" -buildmode=pie"
        ;;
    esac

    cd "${_realname}-${pkgver}"
    go build -ldflags="-s -w -X main.versionString=${pkgver}"
}

check(){
    cd "${_realname}-${pkgver}"
    go test ./... || warning "Tests failed"
}

package() {
    cd "${_realname}-${pkgver}"
    install -Dm755 "moar.exe" "${pkgdir}${MINGW_PREFIX}/bin/moar.exe"
    install -Dm644 "moar.1" "${pkgdir}${MINGW_PREFIX}/share/man/man1/moar.1"
    install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
